package com.ttg.web.controller.common;

import com.ttg.common.entities.BaseResult;
import com.ttg.common.utils.RequestParamsManager;
import com.ttg.model.dto.CMAcctAnalysisDTO;
import com.ttg.model.dto.CostGradingDTO;
import com.ttg.model.dto.CostGradingMerchExportDTO;
import com.ttg.web.service.CostAnalysisService;
import com.ttg.web.service.CostGradingService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;

/**
 * Description：账户成本分解
 * Author: chenyou
 * Date: 2025/9/30 15:19
 * Company: ttg
 * Copyright: Copyright (c) 2025
 */
@Slf4j
@Api("账户成本分析")
@RestController
@RequestMapping("/cost/manage/acct")
public class CostManageAcctAnalysisComtroller {

    @Autowired
    private CostAnalysisService acctAnalysisService;
    @Autowired
    private CostGradingService costGradingService;

    @ApiOperation("成本分解清算")
    @RequestMapping("/acctCostAnalysis")
    public BaseResult acctCostAnalysis(@RequestBody(required = false) String data){
        CMAcctAnalysisDTO reqDto = RequestParamsManager.transformRequestParam(data, CMAcctAnalysisDTO.class);
        return BaseResult.success(acctAnalysisService.acctCostAnalysis(reqDto));
    }

    @ApiOperation("成本分档管控1")
    @RequestMapping("/costGrading")
    public BaseResult costGrading(@RequestBody(required = false) String data){
        CostGradingDTO reqDto = RequestParamsManager.transformRequestParam(data, CostGradingDTO.class);
        return BaseResult.success(costGradingService.costGrading(reqDto));
    }

    @ApiOperation("成本分档-指定分档商户明细导出")
    @RequestMapping("/costGradingMerchExport")
    public void costGradingMerchExport(@RequestBody(required = false) String data,HttpServletResponse response){
        CostGradingDTO reqDto = RequestParamsManager.transformRequestParam(data, CostGradingDTO.class);
        reqDto.setIntervalType("month");
        reqDto.setMerchDimType(0);
        reqDto.setYear("2025");
        reqDto.setMonth("06");
        costGradingService.costGradingMerchExport(reqDto,response);
    }
}
